package com.atguigu.guliguli.product.controller;

import com.atguigu.guliguli.common.utils.PageUtils;
import com.atguigu.guliguli.common.utils.R;
import com.atguigu.guliguli.common.valid.AddGroup;
import com.atguigu.guliguli.common.valid.UpdateGroup;
import com.atguigu.guliguli.product.entity.BrandEntity;
import com.atguigu.guliguli.product.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author: 叶子
 * @date: 2021/11/27 14:54
 **/
@RestController
@RequestMapping("/product/brand")
public class BrandController {
    @Autowired
    BrandService brandService;

    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = brandService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 信息
     * @param brandId
     * @return
     */
    @RequestMapping("/info/{brandId}")
    public R info(@PathVariable("brandId") Long brandId) {
        BrandEntity brand = brandService.getById(brandId);
        return R.ok().put("brand", brand);
    }
    @RequestMapping("/save")
    public R save (@Validated ({AddGroup.class}) @RequestBody BrandEntity brand){
        brandService.save(brand);
        return R.ok();
    }
    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@Validated(UpdateGroup.class) @RequestBody BrandEntity brand){
        brandService.updateDetail(brand);
        return R.ok();
    }
}